<template>
  <div v-if="showMenu" :class="{'header-width':showHeader}" :style="{ maxHeight,top: height }" class="absolute-table-list">
    <template v-for="item in tabs">
      <div
        v-if="!item.isHidden"
        :key="item[idName]"
        :class="['table-list-tabs-item', curIndex === item[idName] ? 'active' : '']"
        @click="handleClick(item[idName])"
      >
        <el-tooltip v-if="item[keyName] && item[keyName].length > 18" :open-delay="800" placement="top" effect="dark">
          <div slot="content" style="max-width:300px">{{ item[keyName] }}</div>
          <div :style="{'font-size': fontSize}" class="item-content">{{ handleName(item[keyName]) }}</div>
        </el-tooltip>
        <div v-else :style="{'font-size': fontSize}" class="item-content">{{ item[keyName] }}</div>
      </div>
    </template>
  </div>
</template>

<script>

export default {
  model: {
    prop: 'curIndex',
    event: 'tabClick'
  },
  props: {
    curIndex: {
      type: Number | String,
      default: 1
    },
    height: {
      type: String,
      default: '48px'
    },
    tabs: {
      type: Array,
      default: () => []
    },
    showMenu: {
      type: Boolean,
      default: false
    },
    showHeader: {
      type: Boolean,
      default: false
    },
    maxHeight: {
      type: String,
      default: 'none'
    },
    fontSize: {
      type: String,
      default: '14px'
    },
    keyName: { // 取值的key
      type: String,
      default: 'name'
    },
    idName: { // 取值的key
      type: String,
      default: 'id'
    }
  },
  data() {
    return {
    };
  },
  methods: {
    handleName(str = '') {
      if (!str) { return ''; }
      if (str.length > 18) {
        return str.slice(0, 18) + '...';
      }
      return str;
    },
    handleClick(id) {
      this.$emit('handleTabClick', id);
    },
    closeMenu() {
      if (this.showMenu) {
        this.$emit('update:showMenu', false);
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.absolute-table-list {
  padding-left: 16px;
  overflow: hidden;
  overflow-y: auto;
  white-space: nowrap;
  display: flex;
  position: absolute;
  top: 48px;
  left: 0;
  background-color: #fff;
  z-index: 999;
  flex-wrap: wrap;
  box-shadow: -1px 8px 12px 0 rgba(0,0,0,0.1);
  border-radius: 0 0 4px 4px;
}
.header-width {
  width: calc(100% - 180px);
}
.table-list-tabs-item {
  height: 100%;
  position: relative;
  margin-right: 32px;
  cursor: pointer;
  font-size: 16px;
  color:#333333;
  white-space: nowrap;
  font-weight:300;
  font-family: PingFangSC-Light, PingFang SC;
  display: flex;
  align-items: center;
  .item-content {
    padding: 15px 0px;
    line-height: 1.15;
    display: flex;
    align-items: center;
  }
  &:first-child {
    margin-left: 0;
  }
  &:last-child {
    margin-right: 0;
  }
  &.active {
    .item-content {
      position: relative;
      color: #406EFF;
      font-weight:500;
      font-family:PingFangSC-Medium,PingFang SC;
    }
  }
}
.dot {
  width: 6px;
  height: 6px;
  margin-left: 2px;
  border-radius: 100%;
  position: relative;
  top: -4px;
}
.down-container {
  height: 48px;
  padding: 0 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
}
.all-tab {
  font-size: 16px;
  color:#333333;
  white-space: nowrap;
  font-weight:300;
  padding-left: 16px;
  padding-right: 10px;
  line-height: 48px;
  font-family: PingFangSC-Light, PingFang SC;
}
@keyframes drop {
  from {top: 0;}
  to {top: 48px;}
}

</style>
